Imports System.Data.SqlClient

Partial Class cn_category_default
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing
    Dim objrdSub As SqlDataReader = Nothing

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim objdt = New GetData
        Dim objdtSub = New GetData
        Dim ps = New PreparedStatement("select * from Category where lang_flag='zh' order by category_name")
        Dim conn As SqlConnection = objdt.getConn()
        objrd = objdt.dr(ps, "", conn, objrd)
        Dim strCat As String
        strCat = ""
        Dim strCatSub As String
        strCatSub = ""
        If objrd.HasRows Then
            Dim con As SqlConnection = objdtSub.getConn()

            While (objrd.Read())
                strCatSub = ""
                Dim psSub = New PreparedStatement("select * from sub_category where category_id= @cid and lang_flag='zh' order by sub_category_name")
                psSub.addParameter("cid", objrd.Item("category_id"))
                objrdSub = objdtSub.dr(psSub, "", con, objrdSub)
                If objrdSub.HasRows Then
                    While (objrdSub.Read())
                        strCatSub &= "<a href=""cn_productslist.aspx?sId=" & objrdSub.Item("sub_category_id") & """>" & objrdSub.Item("sub_category_name") & "</a> |"
                    End While
                End If
                strCat &= "<tr>" & _
                                "<td width=""50%"" valign=""top"">" & _
                                    "<h3><a href=""cn_productslist.aspx?cId=" & objrd.Item("category_id") & """>" & objrd.Item("category_name") & "</a></h3>" & _
                                            "<div style=""line-height:19px;"">" & strCatSub & "" & _
                                            "</div>" & _
                                "</td>"

                If objrd.Read() Then
                    strCatSub = ""
                    psSub.addParameter("cid", objrd.Item("category_id"))
                    objrdSub = objdtSub.dr(psSub, "", con, objrdSub)
                    If objrdSub.HasRows Then
                        While (objrdSub.Read())
                            strCatSub &= "<a href=""cn_productslist.aspx?sId=" & objrdSub.Item("sub_category_id") & """>" & objrdSub.Item("sub_category_name") & "</a> |"
                        End While
                    End If
                    strCat &= "<td width=""50%"" valign=""top"">" & _
                                    "<h3><a href=""cn_productslist.aspx?cId=" & objrd.Item("category_id") & """>" & objrd.Item("category_name") & "</a></h3>" & _
                                        "<div style=""line-height:19px;"">" & strCatSub & "" & _
                                        "</div>" & _
                                "</td>" & _
                            "</tr>"
                Else
                    strCat &= "<td width=""50%"">" & _
                                "</td>" & _
                                "</tr>"

                End If

            End While
            objdtSub.closeConn(con)
        End If
        objdt.closeConn(conn)
        categoryList.InnerHtml = "<table width=""100%"">" & strCat & "</table>"
    End Sub

End Class
